<%--
  Created by IntelliJ IDEA.
  User: cjrh2
  Date: 2025/9/19
  Time: 20:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.6.0.min.js"></script>
</head>
<body>

<table>

    <%--    <form action="/mvc/order" method="post">
            <tr>
                <td>name</td>
                <td><input type="text" id="name" name="name"></td>
            </tr>

            <tr>
                <td>totalprice</td>
                <td><input type="number" id="totalprice" name="totalprice"></td>
            </tr>

            <tr>
                <td>ordertime</td>
                <td><input type="text" id="ordertime" name="ordertime"></td>
            </tr>

            <tr>
                <td>status</td>
                <td><input type="radio" name="status" value="1" checked>已支付
                    <input type="radio" name="status" value="0">未支付
                </td>
            </tr>

            <tr>
                <td>
                    <input type="submit" value="add"><br>
                </td>
            </tr>

        </form>--%>

    <tr>
        <td>name</td>
        <td><input type="text" id="name" name="name"></td>
    </tr>

    <tr>
        <td>totalprice</td>
        <td><input type="number" id="totalprice" name="totalprice"></td>
    </tr>

    <tr>
        <td>ordertime</td>
        <td><input type="text" id="ordertime" name="ordertime"></td>
    </tr>

    <tr>
        <td>status</td>
        <td><input type="radio" name="status" value="1" checked>已支付
            <input type="radio" name="status" value="0">未支付
        </td>
    </tr>

    <tr>
        <td>
            <%--            <input type="submit" value="add"><br>--%>

            <button id="submit_btn">提交</button>
        </td>
    </tr>


</table>


<script>


    $("#submit_btn").click(function () {
        var $name = $("#name").val();
        var $totalprice = $("#totalprice").val();
        var $ordertime = $("#ordertime").val();
        var $status = $(":radio:checked").val();
        // console.log($name + "," + $totalprice + "," + $ordertime + "," + $status);


        var order = {
            'name': $name,
            'totalprice': $totalprice,
            'ordertime': $ordertime,
            'status': $status,
        }


        // console.log(JSON.stringify(order));
        // console.log(order);

        var data = JSON.stringify(order);
        $.ajax({
            url: "/mvc/order",
            type: "post", // GET/POST/PUT/DELETE 等
            data: data, // 发送到服务器的数据,
            contentType: "application/json",
            dataType: "json", // json/xml/html/text/script/jsonp
            success: function (result) { /* 成功回调 */
                if (result.code == 200) {
                    location.href = "http://localhost:8080/mvc/";
                }
            }
        });
    })


</script>

</body>
</html>
